//
// Created by Administrator on 2022/11/20.
//

#include "arrUtil.h"

using namespace std;

vector<int> merge(vector<int> &v, int l, int r, int m)
///
/// \param v 数组
/// \param l 数组左边界
/// \param r 右边界
/// \param m 右边有序的第一个元素的索引
/// \return
{
    vector<int> t;
    if (l < r)
    {
        int i1 = l;
        int i2 = m;
        while (i1 < m and i2 <= r)
        {
            if (v[i1] < v[i2])
            {
//                swapVector(v,i1,i2);
                t.push_back(v[i1]);
                i1++;
            } else
            {
                t.push_back(v[i2]);
                i2++;
            }
        }
        printf("i1=%d, i2=%d\n", i1, i2);
        while (i1 < m)
            t.push_back(v[i1++]);
        while (i2 < r+1)
            t.push_back(v[i2++]);
    }
    return t;

}


int main()
{
    vector<int> arr = {0, 2, 3, 8, 1, 4, 5, 7};
    printVector(merge(arr, 0, arr.size() - 1, 4));
    printVector(arr);
    return 0;
}
